#/usr/local/python36/bin/python3.6

import smtplib, os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.header import Header
from email.utils import parseaddr, formataddr
from email import encoders
import logging,logging.handlers,logging.config ,sys
from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler

logging.config.fileConfig("..\logging.conf")
logger = logging.getLogger("EMAIL")


def send_email(qq,contents):
    user = ''
    pwd = ''
    to = qq
    try:
        msg = MIMEMultipart()
        msg['From'] = user
        msg['To'] = to
        msg['Subject'] = Header(u'kafka lag积累', 'utf-8')

        mime = MIMEText(contents, 'plain', 'utf-8')
        mime.add_header(u'Content-ID', u'<0>')
        mime.add_header(u'X-Attachment-Id', u'0')
        encoders.encode_base64(mime)
        msg.attach(mime)

        server = smtplib.SMTP('smtp.163.com', 25)
        server.set_debuglevel(1)
        server.login(user,pwd)
        server.sendmail(user, to, msg.as_string())
        #print(msg.as_string())
        server.close()
    except BaseException as b:
        _log_err = "send_email函数执行失败 --》" + str(b)
        logger.error(_log_err)

if __name__ == "__main__":
    send_email('','kafka lag积累过多')
